import service from '@/service/userInfo'
import GoodsService from '@/service/eks/goods';
import eciService from '@/service/eci/az'
import store from '@/store/index.js'

export default {
    async get_userinfo() {
        let index = window.location.href.indexOf("token=")
        let token = ""
        if (index > 0) {
            token = window.location.href.substr(index + 6).split("&")[0]
        }
        if (token) {
            store.setToken(token)
        }
        let reqData = {
            token: store.getToken()
        }
        if (sessionStorage.getItem('SYSTEM') == 'eks-op') {
            let resData = await GoodsService.getAuth_info(reqData);
            if (resData.code == "Success") {
                store.setUserInfo(resData.data.user_info)
                store.setAuthRouterInfo(resData.data.permission_dict)
            }
        } else if(sessionStorage.getItem('SYSTEM') == 'eci-op') {
            // 获取eci权限菜单
            let resData = await eciService.getMenuAuth(reqData);
            if (resData.code == "Success") {
                store.setUserInfo(resData.data.user_info)
                store.setAuthRouterInfo(resData.data.permission_dict)
            }
        } else {
            let resData = await service.get_userinfo(reqData)
            if (resData.code == "Success") {
                store.setUserInfo(resData.data.currentInfo.employee)
                store.setUserAuth(resData.data.user_auth)
                store.setAuthRouterInfo(resData.data.permission_dict)
            }
        }
    }
}